package com.itheima.app.mq;

import com.itheima.domain.mongo.Movement;
import com.itheima.domain.mongo.MovementScore;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@SuppressWarnings("all")
public class MovementScoreMQSend {
    @DubboReference
    private MovementService movementService;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    public static final Integer MOVEMENT_PUBLISH = 1;// 发动态
    public static final Integer MOVEMENT_BROWSE = 2;// 浏览动态
    public static final Integer MOVEMENT_LIKE = 3;// 点赞
    public static final Integer MOVEMENT_LOVE = 4;// 喜欢
    public static final Integer MOVEMENT_COMMENT = 5;// 评论
    public static final Integer MOVEMENT_DISLIKE = 6;// 取消点赞
    public static final Integer MOVEMENT_DISLOVE = 7;// 取消喜欢

    public void sendMovement(Long userId,ObjectId publishId,Integer type){
        MovementScore movementScore=new MovementScore();
        movementScore.setDate(System.currentTimeMillis());
        movementScore.setUserId(userId);
        Movement movement = movementService.findById(publishId);
        movementScore.setPublishId(movement.getPid());
        switch (type){
            case 1: {
                movementScore.setScore(20d);
                break;
            }
            case 2: {
                movementScore.setScore(1d);
                break;
            }
            case 3: {
                movementScore.setScore(5d);
                break;
            }
            case 4: {
                movementScore.setScore(8d);
                break;
            }
            case 5: {
                movementScore.setScore(10d);
                break;
            }
            case 6: {
                movementScore.setScore(-5d);
                break;
            }
            case 7: {
                movementScore.setScore(-8d);
                break;
            }
        }
        rocketMQTemplate.convertAndSend("recomment-movement",movementScore);
    }
}
